﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WishClaim.Web.Models
{
    public class EventRepository
    {

        private List<Event> Events()
        {
            if (HttpContext.Current.Session["Events"] == null)
                HttpContext.Current.Session["Events"] = new List<Event>();

            return HttpContext.Current.Session["Events"] as List<Event>;

        }

        public Event GetById(string id)
        {
            return Events().Where(e => e.Key == id).FirstOrDefault();
        }

        public List<Event> GetByEmail(string email)
        {
            return Events().Where(e => e.Members.Where(m => m.Email == email).Count() > 0).ToList();
        } 

        public void Save(Event eEvent)
        {
            Events().Add(eEvent);
        }
    }
}